﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Xml.Serialization;

[XmlRoot()]
public class Perceptron
{
    [XmlElement()]
    public double[] entree;
    public double sortie;
    public double[] poids;
    public double erreur;
    public double potentiel;

    public double alpha;

    public Perceptron()
    {
    }

    public Perceptron(int size, double alpha)
    {
        this.alpha = alpha;
        entree = new double[size + 1];
        poids = new double[size + 1];
        for (int i = 0; i <= size; i++)
        {
            this.poids[i] = new Random().NextDouble();
        }
    }

    public double getSortie
    {
        get { return this.sortie; }

        set { this.sortie = value; }
    }

    public double getEntree(int indice)
    {
       return this.entree[indice - 1];
    }

    public void setEntree(int indice, double value)
    { 
        this.entree[indice - 1] = value; 
    }

    public double getPoids(int indice)
    {
        return this.poids[indice]; 
    }

    public void setPoids(int indice, double value)
    {
        this.poids[indice] = value; 
    }

    public double getErreur
    {
        get { return this.erreur; }

        set { this.erreur = value; }
    }

    public double getPotentiel
    {
        get { return this.potentiel; }
    }

    public void calculPotentiel(double theta)
    {
        this.potentiel = 0;
        for (int i = 0; i <= poids.Length - 1; i++)
        {
            potentiel = potentiel + poids[i] * entree[i];
        }
        potentiel = potentiel - theta;

    }

    public static double activation(double potentiel, double k)
    {
        return 1 / (1 + Math.Exp(-k * potentiel));
    }


    public void calculDeltaPoid()
    {
        for (int i = 0; i <= poids.Length - 1; i++)
        {
            poids[i] = poids[i] - (alpha * erreur * entree[i]);
        }
    }

}